<%@ Page Language="C#" MasterPageFile="~/Master/PlacementManager.master" Theme="YUI"
    StylesheetTheme="YUI" AutoEventWireup="true" CodeFile="ManageUnits.aspx.cs" Inherits="Home_ManageUnits"
    Title="PlacementManager: Courses" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder2" runat="Server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
        </ContentTemplate>
    </asp:UpdatePanel>
    <div class="yui-b">
        <div id="LeftCol">
            <asp:GridView ID="gvUnits" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                DataSourceID="odsUnits" SelectedIndex="0" SkinID="Results" AllowSorting="True"
                DataKeyNames="UnitId" PageSize="20" EmptyDataText="No units have been created."
                OnDataBound="gvUnits_DataBound" OnSelectedIndexChanged="gvUnits_SelectedIndexChanged">
                <Columns>
                    <asp:CommandField ButtonType="Image" SelectImageUrl="~/Images/Icons/edit.gif" ShowSelectButton="True" />
                    <asp:TemplateField HeaderText="Unit Code" SortExpression="UnitCode">
                        <ItemTemplate>
                            <asp:Label ID="lblUnitCode" runat="server" Text='<%# Bind("UnitCode") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="UnitName" HeaderText="Unit Name" SortExpression="UnitName">
                        <ItemStyle Wrap="False" />
                    </asp:BoundField>
                </Columns>
            </asp:GridView>
        </div>
    </div>
    <div id="yui-main">
        <div class="yui-b">
            <h1>
                Manage Units</h1>
            <asp:FormView ID="fvUnit" runat="server" DataSourceID="odsUnit" Width="100%" OnItemInserted="fvUnit_ItemInserted"
                OnItemInserting="fvUnit_ItemInserting" OnItemUpdated="fvUnit_ItemUpdated" OnItemUpdating="fvUnit_ItemUpdating"
                OnModeChanged="fvUnit_ModeChanged">
                <EditItemTemplate>
                    <table style="width: 100%;">
                        <tr>
                            <td style="width: 15%;">
                                <span class="formLabel">Unit Code:</span></td>
                            <td>
                                <asp:TextBox ID="UnitCodeTextBox" CssClass="fullWidthtextBox" runat="server" Text='<%# Bind("UnitCode") %>'>
                                </asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span class="formLabel">Unit Name:</span>
                            </td>
                            <td>
                                <asp:TextBox ID="UnitNameTextBox" CssClass="fullWidthtextBox" runat="server" Text='<%# Bind("UnitName") %>'>
                                </asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span class="formLabel">Year Level:</span>
                            </td>
                            <td>
                                <asp:TextBox ID="YearLevelTextBox" Width="20px" runat="server" Text='<%# Bind("YearLevel") %>'>
                                </asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td valign="top">
                                <span class="formLabel">Description:</span>
                            </td>
                            <td>
                                <asp:TextBox ID="UnitDescriptionTextBox" runat="server" Text='<%# Bind("UnitDescription") %>' Width="300px" Rows="10" TextMode="MultiLine"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <asp:Button ID="UpdateButton" CssClass="inputbutton" runat="server" CausesValidation="True"
                                    CommandName="Update" Text="Update"></asp:Button>
                                <asp:Button ID="UpdateCancelButton" CssClass="inputbutton" runat="server" CausesValidation="False"
                                    CommandName="Cancel" Text="Cancel"></asp:Button></td>
                        </tr>
                    </table>
                    <ajaxToolkit:FilteredTextBoxExtender ID="filtertxtbxEditYearLevel" runat="server"
                        TargetControlID="YearLevelTextBox" ValidChars="0123456789">
                    </ajaxToolkit:FilteredTextBoxExtender>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <table style="width: 100%;">
                        <tr>
                            <td style="width: 15%;">
                                <span class="formLabel">Unit Code:</span></td>
                            <td style="width: 85%;">
                                <asp:TextBox ID="UnitCodeTextBox" CssClass="fullWidthtextBox" runat="server" Text='<%# Bind("UnitCode") %>'>
                                </asp:TextBox></td>
                        </tr>
                        <tr>
                            <td>
                                <span class="formLabel">Unit Name:</span></td>
                            <td>
                                <asp:TextBox ID="UnitNameTextBox" CssClass="fullWidthtextBox" runat="server" Text='<%# Bind("UnitName") %>'>
                                </asp:TextBox></td>
                        </tr>
                        <tr>
                            <td>
                                <span class="formLabel">Year Level:</span></td>
                            <td>
                                <asp:TextBox ID="YearLevelTextBox" Width="20px" runat="server" Text='<%# Bind("YearLevel") %>'>
                                </asp:TextBox></td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <asp:Button ID="InsertButton" CssClass="inputbutton" runat="server" CausesValidation="True"
                                    CommandName="Insert" Text="Insert"></asp:Button>
                                <asp:Button ID="InsertCancelButton" CssClass="inputbutton" runat="server" CausesValidation="False"
                                    CommandName="Cancel" Text="Cancel"></asp:Button></td>
                        </tr>
                    </table>
                    <ajaxToolkit:FilteredTextBoxExtender ID="filtertxtbxInsertYearLevel" runat="server"
                        TargetControlID="YearLevelTextBox" ValidChars="0123456789">
                    </ajaxToolkit:FilteredTextBoxExtender>
                </InsertItemTemplate>
                <ItemTemplate>
                    <table>
                        <tr>
                            <td colspan="2">
                                <h2>
                                    <asp:Label ID="UnitCodeLabel" runat="server" Text='<%# Bind("UnitCode") %>'></asp:Label>
                                    <asp:Label ID="UnitNameLabel" runat="server" Text='<%# Bind("UnitName") %>'></asp:Label>
                                </h2>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span class="formLabel">YearLevel:</span>
                            </td>
                            <td>
                                <asp:Label ID="YearLevelLabel" runat="server" Text='<%# Bind("YearLevel") %>'></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td valign="top">
                                <span class="formLabel">Description:</span></td>
                            <td>
                                <asp:Label ID="UnitDescriptionLabel" runat="server" Text='<%# Bind("UnitDescription") %>'></asp:Label></td>
                        </tr>
                        <tr>
                            <td>
                                <span class="formLabel">DateCreated:</span>
                            </td>
                            <td>
                                <asp:Label ID="DateCreatedLabel" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "DateCreated", "{0:dddd d MMMM yyyy}") %>'></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span class="formLabel">CreatedBy:</span>
                            </td>
                            <td>
                                <asp:Label ID="CreatedByLabel" runat="server" Text='<%# Bind("CreatedBy") %>'></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span class="formLabel">DateUpdated:</span>
                            </td>
                            <td>
                                <asp:Label ID="DateUpdatedLabel" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "DateUpdated", "{0:dddd d MMMM yyyy}") %>'></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span class="formLabel">UpdatedBy:</span>
                            </td>
                            <td>
                                <asp:Label ID="UpdatedByLabel" runat="server" Text='<%# Bind("UpdatedBy") %>'></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <asp:Button ID="EditButton" CssClass="inputbutton" runat="server" CausesValidation="False"
                                    CommandName="Edit" Text="Edit"></asp:Button>
                                <asp:Button ID="NewButton" CssClass="inputbutton" runat="server" CausesValidation="False"
                                    CommandName="New" Text="New"></asp:Button>
                            </td>
                        </tr>
                    </table>
                </ItemTemplate>
            </asp:FormView>
            <asp:Panel ID="pnlCampusesForUnit" runat="server">
                <hr style="height: 1px;" />
                <span class="formLabel">Campuses that offer this unit:</span>
                <asp:GridView ID="gvCampuses" runat="server" AutoGenerateColumns="False" DataSourceID="odsCampuses"
                    OnRowDataBound="gvCampuses_RowDataBound" SkinID="Results" DataKeyNames="CampusId"
                    ShowHeader="False">
                    <Columns>
                        <asp:TemplateField ShowHeader="False">
                            <ItemTemplate>
                                <asp:CheckBox ID="cbUnitCampusAssociation" runat="server" />
                            </ItemTemplate>
                            <ItemStyle Width="40px" />
                        </asp:TemplateField>
                        <asp:BoundField DataField="CampusName" HeaderText="CampusName" ShowHeader="False"
                            SortExpression="CampusName" />
                    </Columns>
                </asp:GridView>
                <asp:Button ID="btnSaveCampusChanges" runat="server" CssClass="inputbutton" OnClick="btnSaveCampusChanges_Click"
                    Text="Save Campus Changes" />
            </asp:Panel>
        </div>
    </div>
    <!--Object Data Sources ************************************************* -->
    <asp:ObjectDataSource ID="odsUnits" runat="server" OldValuesParameterFormatString="original_{0}"
        SelectMethod="SelectAllWDivisionId" TypeName="PlacementManager.UnitComponent"
        SortParameterName="sortExpression">
        <SelectParameters>
            <asp:SessionParameter DefaultValue="1" Name="DivisionId" SessionField="DivisionId"
                Type="Int32" />
            <asp:Parameter DefaultValue="UnitCode" Name="sortExpression" Type="String" />
        </SelectParameters>
    </asp:ObjectDataSource>
    <asp:ObjectDataSource ID="odsUnit" runat="server" DataObjectTypeName="PlacementManager.Unit"
        InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" SelectMethod="SelectOne"
        TypeName="PlacementManager.UnitComponent" UpdateMethod="Update" OnInserted="odsUnit_Inserted">
        <SelectParameters>
            <asp:ControlParameter ControlID="gvUnits" Name="UnitId" PropertyName="SelectedValue"
                Type="Int32" />
        </SelectParameters>
    </asp:ObjectDataSource>
    <asp:ObjectDataSource ID="odsCampuses" runat="server" OldValuesParameterFormatString="original_{0}"
        SelectMethod="SelectAll" TypeName="PlacementManager.CampusComponent">
        <SelectParameters>
            <asp:Parameter DefaultValue="CampusCode" Name="sortExpression" Type="String" />
        </SelectParameters>
    </asp:ObjectDataSource>
</asp:Content>
